package com.xuecheng.content.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xuecheng.commons.model.dto.CourseDto;
import com.xuecheng.commons.model.dto.PageRequest;
import com.xuecheng.commons.model.vo.PageResponseResult;
import com.xuecheng.commons.model.vo.ResponseResult;
import com.xuecheng.content.domain.CourseBase;
import com.xuecheng.content.mappers.CourseBaseMapper;
import com.xuecheng.content.service.CourseBaseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 课程基本信息 服务实现类
 * </p>
 *
 * @author xuecheng
 * @since 2022-04-20
 */
@Service
public class CourseBaseServiceImpl extends ServiceImpl<CourseBaseMapper, CourseBase> implements CourseBaseService {

    @Override
    public ResponseResult courseList(PageRequest request, CourseDto dto) {

        //查询条件
        LambdaQueryWrapper<CourseBase> qw = new LambdaQueryWrapper<>();
        if (!ObjectUtil.isEmpty(dto.getCourseName())) {
            qw.like(CourseBase::getName, "%" +dto.getCourseName() + "%");
        }
        if (!ObjectUtil.isEmpty(dto.getTeachmode())) {
            qw.eq(CourseBase::getTeachmode, dto.getTeachmode());

        }
        if (!ObjectUtil.isEmpty(dto.getAuditStatus())) {
            qw.eq(CourseBase::getAuditStatus, dto.getAuditStatus());
        }
        qw.eq(CourseBase::getStatus, 1);  //只查询未删除的
        //获取分页参数
        Integer pageNo = request.getPageNo();
        Integer pageSize = request.getPageSize();
        //调佣分页查询
        Page<CourseBase> pageparms = new Page<>(pageNo, pageSize);
        IPage<CourseBase> page = this.page(pageparms, qw);
        //构造返回
        return PageResponseResult.okResult(page.getTotal(), page.getRecords());//总条数
    }
}
